package com.ggb.controller;

/**
 * Created with IntelliJ IDEA.
 *
 * @User: GGB
 * @Date: 2021/12/2
 * @Description
 */
import com.ggb.entry.User;
import com.ggb.entry.UserVO;
import com.ggb.feign.UserFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/user")
public class UserHandler {

    @Autowired
    private UserFeign userFeign;

    @GetMapping("/findAll")
    @ResponseBody
    public UserVO findAll(@RequestParam("page") int page, @RequestParam("limit") int limit) {
        return userFeign.findAll(page, limit);
    }

    @GetMapping("/redirect/{location}")
    public String redirect(@PathVariable("location") String location){
        return location;
    }

    @PostMapping("/save")
    public String save(User user) {
        userFeign.save(user);
        return "redirect:/user/redirect/user_manage";
    }

    @GetMapping("/deleteById/{id}")
    public String deleteById(@PathVariable("id") long id) {
        userFeign.deleteById(id);
        return "redirect:/user/redirect/user_manage";
    }
}
